<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set value="<%=request.getContextPath()%>" var="ctx"></c:set>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>商家信息管理</title>

<style type="text/css">
/* 	body { font-size: 140%; } */
div.DTTT {
	margin-bottom: 0.5em;
	float: right;
}

div.dataTables_wrapper {
	clear: both;
}
</style>
<link rel="stylesheet" type="text/css" href="${ctx}/decorators/css/plugins/toastr/toastr.min.css"></link>
<script src="${ctx}/decorators/js/plugins/toastr/toastr.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	var table =$('#example').dataTable({
    	"oLanguage" : { // 汉化
    		"sProcessing" : "正在加载数据...",
    		"sLengthMenu" : "_MENU_ 记录/页",
    		"sZeroRecords" : "没有您要搜索的内容",
    		"sInfo" : "显示第_START_ 至 _END_ 条记录 ，共 _TOTAL_ 项",
    		"sInfoEmpty" : "记录数为0",
    		"sInfoFiltered" : "(全部记录数 _MAX_  条)",
    		"sInfoPostFix" : "",
    		"sSearch" : "查找&#8194;",
    		"sUrl" : "",
    		"oPaginate" : {
    		"sFirst" : "第一页",
    		"sPrevious" : " 上一页 ",
    		"sNext" : " 下一页 ",
    		"sLast" : " 最后一页 "
    		}
    		}
    });
    var tt = new $.fn.dataTable.TableTools( table );
    
    $( tt.fnContainer() ).insertBefore('div.dataTables_wrapper');
});


/**
 * 修改厂商
 */
function editVendor(vendorId){
	window.location.href = "editVendor?id="+vendorId;
}

/**
 * 删除
 */
function delVendor(){
	var vendorId = document.getElementById("vendorIdDel").value;
	$.ajax({
           type: "POST",
           url: "deleteVendor",  //换成你要请求的action, paperId 是url参数
           data: {'id':vendorId},
           dateType:'text',
           success: function(msg){
        	    document.getElementById("alertDel").innerHTML = "删除成功！";
        	    document.location.reload();
           },
           error: function(msg){
           		toastr.error("删除失败！")
           }
      });
}

function deleteId(id){
	document.getElementById("alertDel").innerHTML = "";
	$.ajax({
        type: "post",
        url: "countProduct",  //换成你要请求的action, paperId 是url参数
        data: {'vId':id},
        success: function(msg){
        	if(msg == "success"){
        		document.getElementById("alertDel").innerHTML = "确定删除该条厂商信息吗？";
        		$("#delBtn").attr("disabled",false);
        	}else{
        		document.getElementById("alertDel").innerHTML = "请先删除所属产品信息！";
        		$("#delBtn").attr("disabled",true);
        	}
        },
        error: function(msg){
        		toastr.error("删除失败！")
        }
   });
	document.getElementById("vendorIdDel").value = id;
}

/**
 * 查看厂商下的产品信息
 */
function checkVendor(id){
	window.location.href = "${ctx}/admin/productList?vId="+id;
}

</script>

</head>
<body>
      <div class="row">
            <div class="col-lg-12">
               <div class="row wrapper border-bottom white-bg ibox-title">
                         <div class="col-lg-11">
                             <h3>商家管理</h3>
                         </div>
                         <div class="col-lg-1">
                             <a class="btn btn-success btn-block"  href="${ctx}/admin/insertVendor">新增厂商</a>
                         </div>
                   </div>


             <div class="wrapper wrapper-content animated fadeInRight">
               <div class="ibox-title">
				<table id="example" class="table table-bordered table-hover text-center">
					<thead>
						<tr>
							<th class="text-center">编号</th>
							<th class="text-center">公司名称</th>
							<th class="text-center">公司网址</th>
							<th class="text-center">联系人</th>
							<th class="text-center">公司地址</th>
							<th class="text-center">联系电话</th>
							<th class="text-center">操作</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${vendorList }" var="vendor"
							varStatus="status">
							<tr id='${vendor.id}'>
								<td>${status.index+1 }</td>
								<td><a href="${ctx}/admin/productList?vId=${vendor.id}">${vendor.VName}</a></td>
								<td>${vendor.website}</td>
								<td>${vendor.linkman}</td>
								<td>${vendor.address}</td>
								<td>${vendor.tel}</td>
								<td>
									<a onclick="editVendor(${vendor.id})" class="btn btn-white btn-sm">
										<i class="fa fa-pencil"></i>&#8194;编辑
									</a>
									<a onclick="checkVendor(${vendor.id})" class="btn btn-white btn-sm">
										<i class="fa fa-folder"></i>&#8194;查看
									 </a>
									<a onclick="deleteId(${vendor.id})" data-toggle="modal" data-target="#delModal" class="btn btn-white btn-sm">
									   <i class="fa fa-trash-o"></i>&#8194;删除
									</a>											
								</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
	<script type="text/javascript">
		$(function(){
	        //状态改变
	        $(".btn_manage").click(function() {
	        	var id = $(this).parent().parent().attr('id');
	        	$.ajax({
	        		url : "dreamComeTrue.action",
	        		type : "post",
	        		data : "id=" + id ,
	        		dataType : "json",
	        		success : function(data) {
	        			if (data.success) {
	        				 location.reload();
	        			}
	        		}
	        	});
	        });
	   });
	</script>

	<!-- Button trigger modal -->


	<!-- 删除的模态层 -->
	<div class="modal fade" id="delModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">提示</h4>
				</div>
				<div class="modal-body" id="alertDel">确定删除该条厂商信息吗？</div>
				<div class="modal-footer">
					<input type="hidden" id="vendorIdDel" />
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" onclick="delVendor()" class="btn btn-primary"
						id="delBtn">删除</button>
				</div>
			</div>
		</div>
	</div>

</body>
</html>